package com.lc1993929.chapter18.CAD;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by LiuChang on 2018/8/16.
 */
public class StoreCADState {
    public static void main(String[] args) throws IOException {
        List<Class<? extends Shape>> shapeTypes =
                new ArrayList<>();
        //    Add references to the class objects;
        shapeTypes.add(Circle.class);
        shapeTypes.add(Square.class);
        shapeTypes.add(Line.class);
        List<Shape> shapes = new ArrayList<>();
        //    Make some shapes;
        for (int i = 0; i < 10; i++) {
            shapes.add(Shape.randomFactory());
        }
        //    Set all the static colors to GREEN;
        for (int i = 0; i < 10; i++) {
            shapes.get(i).setColor(Shape.GREEN);
        }
        //    Save the state vector;
        ObjectOutputStream out = new ObjectOutputStream(
                new FileOutputStream("CADState.out")
        );
        out.writeObject(shapeTypes);
        Line.serializeStaticState(out);
        out.writeObject(shapes);
        //    Display the shapes;
        System.out.println(shapes);
    }
}
